<template>
  <div class="goods-wrapper">
    <input type="checkbox" class="goods-checked" :checked="state" @change="stateHandler">
    <!--  右侧:图片+信息-->
    <div class="goods-info">
      <img :src="image" class="goods-image">
      <div class="goods-des">
        <span class="goods-description">{{ description }}</span>
        <div class="goods-price-number">
          <span>${{ price / 100 }}</span>
<!--          使用插槽，让Count组件和App组件不再是爷孙关系-->
<!--          <slot></slot>  此为默认插槽-->
          <slot name="count"></slot>  <!-- 此为具名插槽 -->
<!--          <Count :num="num" :id="id"></Count>-->
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
  import { Component, Prop, Vue } from 'vue-property-decorator';

  @Component({
    name: 'Goods'
  })
  export default class HelloWorld extends Vue {
      /* props */
      @Prop() private title!: string;
      @Prop() private description!: string;
      @Prop() private image!: string;
      @Prop() private state!: boolean;
      @Prop() private price!: number;
      @Prop() private id!: number;
      // @Prop() private num!: number;

      /* data */

      /* methods */
      stateHandler(e: any) {
          const state = e.target.checked;
          this.$emit('stateChange', {id: this.id, state})
      }
  }
</script>

<style scoped lang="less">
  .goods-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
  }
  .goods-description {
    font-size: 14px;
    text-align: left;
  }
  .goods-info {
    width: 100%;
    margin-left: 10px;
    display: flex;
    .goods-image {
      width: 120px;
      height: 120px;
      margin-right: 10px;
    }
    &>div {
      width: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: flex-start;
      .goods-price-number {
        width: 100%;
        display: flex;
        justify-content: space-between;
      }
    }

  }
</style>
